package com.taotao.manage.service;

import com.taotao.manage.pojo.Item;
import com.taotao.manage.pojo.ItemDesc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * java类简单作用描述
 *
 * @ProjectName: taotao
 * @Package: com.taotao.manage.service
 * @ClassName: ${TYPE_NAME}
 * @Description: java类作用描述
 * @Author: 作者姓名
 * @CreateDate: 2018/4/21 22:29
 * @UpdateUser: Neil.Zhou
 * @UpdateDate: 2018/4/21 22:29
 * @UpdateRemark: The modified content
 * @Version: 1.0
 * <p>
 * Copyright: Copyright (c) 2018
 */
@Service
public class ItemService extends BaseService<Item> {

    @Autowired
    private ItemDescService itemDescService;

    public void insertItemAndItemDesc(Item item,String desc){
        item.setId(null);
        this.saveSelective(item);

        ItemDesc record = new ItemDesc();
        record.setItemId(item.getId());
        record.setItemDesc(desc);
        itemDescService.saveSelective(record);
    }

    public boolean updateItemAndItemDesc(Item item,String desc){
        //强制设置不能更新的字段
        item.setStatus(null);
        Integer count1 = super.updateSelective(item);
        //创建商品详情
        ItemDesc record = new ItemDesc();
        record.setItemId(item.getId());
        record.setItemDesc(desc);
        Integer count2 = itemDescService.updateSelective(record);
        return count1==1&&count2==1;
    }
}
